<template>
  <div>
    <h2>添加员工</h2>
    员工名称<input type="text" v-model="username">
    员工密码<input type="text" v-model="password">
    员工部门<select v-model="depart">
      <option v-for="i in departs" :key="i.id" :value="i.id">{{i.name}}</option>
    </select>
    <button @click="sub">添加</button>
  </div>
</template>

<script>
export default {
  data(){
    return{
      username:'',
      password:'',
      depart:0,
      departs:[]
    }
  },
  mounted(){
    this.axios({
      url:'http://127.0.0.1:8000/app01/depart/',
      method:'get',

    }).then(res=>{
      this.departs=res.data.data;
    })
  },
  methods:{
    sub:function(){
      let auth=localStorage.getItem('auth');
      let data={
        username:this.username,
        password:this.password,
        depart:this.depart,
        auth:auth
      }
      this.axios({
        url:'http://127.0.0.1:8000/app01/user/',
        method:'post',
        data:data
      }).then(res=>{
        if(res.data.code==1000){
          this.$router.push('/User')
        }else{
          alert(res.data.msg)
        }
      })
    }
  }
}
</script>

<style>

</style>
